import axios from "~/axios";
import { queryFilters } from "~/composables/util";


// 获取媒体分类列表
export function getMediasCategoryList() {
    return axios.get(`/medias/medias_category/`)
}

// 获取媒体列表
export function getMediasList({ ...data }) {
    let r = queryFilters(data)
    return axios.get(`/medias/list/${r}`)
}

// 获取媒体详情
export function getReadMedias(id) {
    return axios.get(`/medias/list/${id}/`)
}

// 新增媒体列表
export function postMedias(data) {
    // if (data.covers.length) {
    //     data.covers_ids = data.covers.map((o) => o.id)
    // }

    return axios.post(`/medias/list/`, data)
}

// 编辑媒体
export function putMedias(id, data) {
    if (data.covers) {
        data.covers_ids = data.covers.map((o) => o.id)
    }
    if (data.media_images) {
        data.media_images_ids = data.media_images.map((o) => o.id)
    }
    if (data.media_videos) {
        data.media_videos_ids = data.media_videos.map((o) => o.id)
    }
    console.log("putMedias",data)
    return axios.put(`/medias/list/${id}/`, data)
}

// 批量修改媒体审核状态
export function patchMediasSubmit(id,data) {
    return axios.patch(`/medias/list/process_all/`,{id,data})
}

// 批量审核媒体
export function patchMediasData(ids, data) {
    ids = Array.isArray(ids) ? ids : [ids]
    console.log("data",data)
    return axios.patch(`/medias/list/process_all/`, { ids, data })
}

// 批量删除媒体
export function deleteMedias(ids) {
    ids = Array.isArray(ids) ? ids : [ids]
    return axios.post(`/medias/list/delete_all/`, { ids })
}